package com.resys.server.controller.admin;

import com.resys.entity.po.Device;
import com.resys.entity.query.DeviceQuery;
import com.resys.entity.vo.ResponseVO;
import com.resys.server.controller.ABaseController;
import com.resys.service.DeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController("DeviceController")
@Slf4j
@Api(tags = "管理员模块-设备管理接口")
@RequestMapping("/admin/device")
public class DeviceController extends ABaseController {
       @Resource
       private DeviceService deviceService;
       @ApiOperation("获取设备列表")
       @GetMapping
       public ResponseVO list() {
           DeviceQuery query = new DeviceQuery();
           List<Device> list =  deviceService.findListByParam(query);
           return getSuccessResponseVO(list);
       }
       @ApiOperation("添加设备")
       @PostMapping
       public ResponseVO add(String name) {
           Device device = new Device();
           device.setName(name);
           deviceService.add(device);
           return getSuccessResponseVO("添加成功");
       }
       @ApiOperation("删除设备")
       @PostMapping("/delete")
       public ResponseVO delete(Integer deviceId) {
           deviceService.deleteDeviceByDeviceId(deviceId);
           return getSuccessResponseVO("删除成功");
       }
}
